package modelUtil;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import paginas.PaginaEntornoCreacionTeclados;
import paginas.PaginaUsuarios;
import plantilla.AccionBotonTO;
import plantilla.BotonTO;
import plantilla.PlantillaTO;
import usuario.usuarioTO.UsuarioTO;
import util.AccionesEjecutar;
import util.BotonPersonalizado;
import util.TecladoReal;
import AccionBoton.AccionAceptarClaveAdmin;
import AccionBoton.AccionAdmin;
import AccionBoton.AccionCerrar;
import AccionBoton.AccionFocoCreditos;
import AccionBoton.AccionIrTeclado;
import AccionBoton.AccionLanzarAyuda;
import AccionBoton.AccionPulsarBoton;
import AccionBoton.AccionSeleccionBoton;
import AccionBoton.accionRaton;
import fachadaPlantilla.delegate.PlantillaFacade;

@SuppressWarnings("unused")
public class Util {

    private static int s = -1;

	
	public static void copyFiles(File srcDir, File dstDir, boolean blOverwrite)
			throws IOException {

		if (srcDir.isDirectory()) {
			if(!srcDir.getName().equals(".svn")){

			if (!dstDir.exists()) {
				dstDir.mkdir();
			}
			String[] children = srcDir.list();
			for (int i = 0; i < children.length; i++) {
				copyFiles(new File(srcDir, children[i]), new File(dstDir,
						children[i]), blOverwrite);
			}}
		} else {

			copyFile(srcDir, dstDir, blOverwrite);
		}
	}

	public static void copyFile(File src, File dst, boolean blOverwrite)
			throws IOException {

		if (blOverwrite) {
			InputStream in = new FileInputStream(src);
			OutputStream out = new FileOutputStream(dst);

			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0) {
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
		} else {
			if (!dst.exists()) {

				InputStream in = new FileInputStream(src);
				OutputStream out = new FileOutputStream(dst);

				byte[] buf = new byte[1024];
				int len;
				while ((len = in.read(buf)) > 0) {
					out.write(buf, 0, len);
				}
				in.close();
				out.close();

			}

		}
	}

	public static void addTextElement(Document doc, Element nodeParent,
			String strTag, String strValue) {
		Element nodeElem = doc.createElement(strTag);
		nodeElem.setTextContent(strValue);
		nodeParent.appendChild(nodeElem);
	}

	public static void borrarDirectorio(File directorio) {

		File[] ficheros = directorio.listFiles();

		for (int x = 0; x < ficheros.length; x++) {
			if (ficheros[x].isDirectory()) {
				borrarDirectorio(ficheros[x]);
			}
			ficheros[x].delete();
		}
		directorio.delete();
	}

	public static BotonPersonalizado BotonImagen(String nombre, String imagen) {

		BotonPersonalizado boton = new BotonPersonalizado();
		boton.setColorMouseOver(Color.orange);
		GridBagLayout grid3 = new GridBagLayout();
		GridBagConstraints cons = new GridBagConstraints();
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		
		
		
		
		boton.setName(nombre);

		boton.getLabelImagen().setHorizontalAlignment(SwingConstants.CENTER);
		boton.getLabelImagen().setVerticalAlignment(SwingConstants.CENTER);

		boton.getLabelTexto().setHorizontalAlignment(SwingConstants.CENTER);
		boton.getLabelTexto().setVerticalAlignment(SwingConstants.CENTER);

		boton.getLabelTexto().setText(nombre);
		boton.getLabelTexto().setForeground(Color.black);
		//boton.getLabelTexto().setFont(new Font(botonInfo.getNombreFuente(), Font.PLAIN, new Integer(botonInfo.getTamanoFuente())));

		ImageIcon imagenicono = new ImageIcon(imagen);

    	int alto = imagenicono.getIconHeight();
    	int ancho = imagenicono.getIconWidth();
    	//double factorEscala = (double)11*(alto /  ((screenSize.getHeight() /3) - 80));

		//ancho = ((int) (ancho / factorEscala));
		//alto = ((int) (alto / factorEscala));
		Image redimensionada = imagenicono.getImage().getScaledInstance(ancho,
				alto, Image.SCALE_DEFAULT);
		//imagenicono = new ImageIcon(redimensionada);
				
		boton.getLabelImagen().setIcon(imagenicono);
		boton.setLayout(grid3);
     	cons.fill = GridBagConstraints.BOTH;
        cons.weightx = 1.0;
        cons.weighty = 1.0;
        cons.gridx=0;
        cons.gridy=0;
        grid3.setConstraints(boton.getLabelTexto(), cons);
        cons.gridx=0;
        cons.gridy=0;
        grid3.setConstraints(boton.getLabelImagen(), cons);

		boton.add(boton.getLabelTexto());
		boton.add(boton.getLabelImagen());

		boton.addMouseListener(new accionRaton(boton, Color.orange));

		return boton;
	}
	
	
	public static BotonPersonalizado BotonPequeno(String nombre, String imagen) {

		BotonPersonalizado boton = new BotonPersonalizado();
		boton.setColorMouseOver(Color.orange);
		boton.setPreferredSize(new Dimension(50,30));
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();


		boton.getLabelTexto().setHorizontalAlignment(SwingConstants.CENTER);
		boton.getLabelImagen().setHorizontalAlignment(SwingConstants.CENTER);
		boton.getLabelTexto().setText(nombre);
		boton.getLabelTexto().setFont(new Font("fuente", Font.BOLD, 12));
		ImageIcon imagenicono = new ImageIcon(imagen);

		int ancho = imagenicono.getIconWidth();
		int alto = imagenicono.getIconHeight();

		/*double factorEscala = alto / ((screenSize.getHeight() / 3) - 80);
		ancho = ((int) (ancho / factorEscala));
		alto = ((int) (alto / factorEscala));
		Image redimensionada = imagenicono.getImage().getScaledInstance(ancho,
				alto, Image.SCALE_DEFAULT);*/
		
		

		//label.setIcon(new ImageIcon(redimensionada));
		boton.getLabelImagen().setIcon(imagenicono);
		/*grid2.setHorizontalGroup(grid2.createParallelGroup()
				.addComponent(label).addComponent(label1));
		grid2.setVerticalGroup(grid2.createSequentialGroup()
				.addComponent(label).addComponent(label1));*/
		

		/*boton.setMinimumSize(new Dimension(
				(int) (screenSize.getWidth() / 5) - 10, (int) (screenSize
						.getHeight() / 3) - 20));
		boton.setMaximumSize(new Dimension(
				(int) (screenSize.getWidth() / 5) - 10, (int) (screenSize
						.getHeight() / 3) - 20));
		boton.setSize(new Dimension(
				(int) (screenSize.getWidth() / 5) - 10, (int) (screenSize
						.getHeight() / 3) - 20));*/
		boton.setBorder(new LineBorder(Color.black, 2));
		boton.addMouseListener(new accionRaton(boton, Color.orange));

		return boton;
	}
	
	
	
	public static BotonPersonalizado BotonUsuario(String nombre, String imagen) {




		if(imagen.equals(""))imagen = "lib//user.png";
		ImageIcon imagenicono = new ImageIcon(imagen);

		int ancho = imagenicono.getIconWidth();
		int alto = imagenicono.getIconHeight();

		BotonPersonalizado boton = new BotonPersonalizado();
		boton.setBorder(new LineBorder(Color.black, 10));
		boton.addMouseListener(new accionRaton(boton, Color.orange));
		boton.setColorMouseOver(Color.orange);
		GridBagLayout grid3 = new GridBagLayout();
		GridBagConstraints cons = new GridBagConstraints();

		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		
		boton.getLabelTexto().setFont(new Font("fuente", Font.BOLD, 26));
		
		
		boton.setName(nombre);

		boton.getLabelImagen().setHorizontalAlignment(SwingConstants.CENTER);
		boton.getLabelImagen().setVerticalAlignment(SwingConstants.TOP);

		boton.getLabelTexto().setHorizontalAlignment(SwingConstants.CENTER);
		boton.getLabelTexto().setVerticalAlignment(SwingConstants.BOTTOM);

		boton.getLabelTexto().setText(nombre);
		boton.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_usuarios") + boton.getLabelTexto().getText());
		boton.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_usuarios") + boton.getLabelTexto().getText());

		boton.getLabelTexto().setForeground(Color.black);


				
		boton.getLabelImagen().setIcon(imagenicono);
		boton.setLayout(grid3);
     	cons.fill = GridBagConstraints.BOTH;
        cons.weightx = 1.0;
        cons.weighty = 1.0;
        cons.gridx=0;
        cons.gridy=0;
        grid3.setConstraints(boton.getLabelTexto(), cons);
        cons.gridx=0;
        cons.gridy=0;
        grid3.setConstraints(boton.getLabelImagen(), cons);

		boton.add(boton.getLabelTexto());
		boton.add(boton.getLabelImagen());
		boton.setEnabled(false);
		return boton;
	}
	
	public static void popup(int tipo, String mensaje) {
		JDialog ventana = new JDialog();
		BotonPersonalizado aceptar = BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_aceptar"), "lib//Aceptar.png");
		aceptar.addFocusListener(new AccionFocoCreditos(aceptar));
		aceptar.addActionListener(new AccionCerrar(ventana));
		aceptar.setBackground(Color.LIGHT_GRAY);
		aceptar.setPreferredSize(new Dimension(150,50));
		GridBagLayout grid = new GridBagLayout();
		GridBagConstraints cons = new GridBagConstraints();
		JPanel panel = new JPanel();
		JPanel panel2 = new JPanel();
		aceptar.addKeyListener(new AccionPulsarBoton(aceptar));
		FlowLayout orden = new FlowLayout(FlowLayout.CENTER);
		FlowLayout orden2 = new FlowLayout(FlowLayout.CENTER);
		panel.setLayout(orden);
		panel2.setLayout(orden2);
		
		int tamanho = mensaje.length();
		ventana.setModal(true);
		ventana.setBounds(0, 0, (tamanho * 10) + 150, 150);
		ventana.setLocationRelativeTo(null);
		ventana.setResizable(false);
		ImageIcon icono;
		if (tipo == 0) {
			icono = new ImageIcon("lib/error.png");
			ventana.setTitle("Error");
		} else {
			icono = new ImageIcon("lib/info.png");
			ventana.setTitle("Informacion");
		}
		JLabel label = new JLabel(mensaje);
		label.setBounds(5, 10, (tamanho * 10), 20);
		label.setVisible(true);
		label.setIcon(icono);

		orden.addLayoutComponent("label", label);
		panel.add(label);
		orden2.addLayoutComponent("boton", aceptar);
		panel2.add(aceptar);
		
		ventana.setLayout(grid);
		cons.gridheight = 1;
		cons.gridwidth = 1;
		cons.gridx = 0;
		cons.gridy = 0;
		grid.addLayoutComponent(panel, cons);
		ventana.add(panel);
		cons.gridy = 1;
		grid.addLayoutComponent(panel2, cons);
		ventana.add(panel2);
		ventana.setAlwaysOnTop(true);
		ventana.setVisible(true);
	}
	
	public static void filechooser(JPanel parent){
		
	    JFileChooser chooser = new JFileChooser();
	    // Note: source for ExampleFileFilter can be found in FileChooserDemo,
	    // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
	   /* ExampleFileFilter filter = new ExampleFileFilter();
	    filter.addExtension("jpg");
	    filter.addExtension("gif");
	    filter.setDescription("JPG & GIF Images");
	    chooser.setFileFilter(filter);*/
	    int returnVal = chooser.showOpenDialog(parent);
	    if(returnVal == JFileChooser.APPROVE_OPTION) {

	    }

		
		
	}
	
	public static void menuAdmin(UsuarioTO user,JFrame frame){
		
		JDialog ventana = new JDialog();
		GridBagLayout orden = new GridBagLayout();
		GridBagConstraints cons = new GridBagConstraints();
		ventana.setLayout(orden);
     	cons.fill = GridBagConstraints.BOTH;
        cons.weightx = 1.0;
        cons.weighty = 1.0;
        cons.gridx = 0;
        cons.gridy = 0;
        cons.insets = new Insets(10, 0, 0, 0);
		JLabel label1 = new JLabel(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_nombre"));
		label1.setFont(new Font("Verdana", Font.BOLD, 14));
		orden.addLayoutComponent(label1, cons);
		ventana.add(label1);
		cons.gridx = 1;
		cons.gridy = 0;
		JLabel label2 = new JLabel(user.getNombre());
		orden.addLayoutComponent(label2, cons);
		ventana.add(label2);
		

		
		cons.gridx = 0;
		cons.gridy = 1;
		JLabel label3 = new JLabel(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_clave"));
		label3.setFont(new Font("Verdana", Font.BOLD, 14));

		orden.addLayoutComponent(label3, cons);
		ventana.add(label3);
		
		cons.gridx = 1;
		cons.gridy = 1;
		/*JLabel label4 = new JLabel("Clave2");
		label4.setFont(new Font("Verdana", Font.BOLD, 14));

		orden.addLayoutComponent(label4, cons);
		ventana.add(label4);*/
		cons.gridwidth = 2;
		JPasswordField texto1 = new JPasswordField();
		texto1.getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_popup_campo_password"));
		texto1.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_popup_campo_password"));
		texto1.addKeyListener(new AccionAceptarClaveAdmin(user,texto1,frame,ventana));

		orden.addLayoutComponent(texto1, cons);
		ventana.add(texto1);
		cons.gridwidth=1;
		cons.gridx = 0;
		cons.gridy = 2;
		BotonPersonalizado boton1 = BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_ayuda"),"lib//help.png");
		int alto = boton1.getLabelImagen().getIcon().getIconHeight();
		int ancho = boton1.getLabelImagen().getIcon().getIconWidth();

		double factorEscala = (double)(alto /  32);

		ancho = ((int) (ancho / factorEscala));
		alto = ((int) (alto / factorEscala));
		ImageIcon imagen = new ImageIcon("lib//help.png");
		Image redimensionada = imagen.getImage().getScaledInstance(ancho, alto, Image.SCALE_DEFAULT);
		boton1.getLabelImagen().setIcon(new ImageIcon(redimensionada));
		boton1.setMnemonic(KeyEvent.VK_Y);
		boton1.addFocusListener(new AccionFocoCreditos(boton1));
		boton1.getLabelTexto().setDisplayedMnemonic(KeyEvent.VK_Y);
		boton1.addActionListener(new AccionLanzarAyuda(frame));
		boton1.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_menu_ayuda"));
		boton1.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_menu_ayuda"));
		boton1.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
		boton1.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);
		boton1.setPreferredSize(new Dimension(80,30));
		boton1.setBackground(new Color(238, 238, 238));
		//boton1.setBorder(null);
		orden.addLayoutComponent(boton1, cons);
		ventana.add(boton1);
		
		cons.gridx = 1;
		cons.gridy = 2;
		BotonPersonalizado boton2 = BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_aceptar"),"lib//Aceptar.png");
		boton2.setPreferredSize(new Dimension(80,30));
		boton2.setMnemonic(KeyEvent.VK_A);
		boton2.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_password_aceptar"));
		boton2.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_password_aceptar"));
		boton2.getLabelTexto().setDisplayedMnemonic(KeyEvent.VK_A);
		boton2.addFocusListener(new AccionFocoCreditos(boton2));
		boton2.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
		boton2.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);

		boton2.setBackground(new Color(238, 238, 238));

		//boton2.setBorder(null);

		boton2.addActionListener(new AccionAdmin(user,texto1,frame,ventana));
		orden.addLayoutComponent(boton2, cons);
		ventana.add(boton2);
		
		cons.gridx = 2;
		cons.gridy = 2;
		BotonPersonalizado boton3 = BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_cancelar"),"lib//cancelar.png");
		boton3.setPreferredSize(new Dimension(80,30));
		boton3.setMnemonic(KeyEvent.VK_C);
		boton3.getLabelTexto().setDisplayedMnemonic(KeyEvent.VK_C);
		boton3.addFocusListener(new AccionFocoCreditos(boton3));
		boton3.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_password_cancelar"));
		boton3.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_password_cancelar"));
		boton3.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
		boton3.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);

		boton3.setBackground(new Color(238, 238, 238));

		//boton3.setBorder(null);
		boton3.addActionListener(new AccionCerrar(ventana));
		boton3.addActionListener(new AccionIrTeclado(frame, "Usuarios", null));
		orden.addLayoutComponent(boton3, cons);
		ventana.add(boton3);


		
		
		int tamanho = 3*user.getNombre().length();

		ventana.setBounds(0, 0, (tamanho * 10) + 300, 2*75);

		ventana.setLocationRelativeTo(null);
		//ventana.setResizable(false);
		ventana.setModal(true);
		ImageIcon icono;



		//orden.addLayoutComponent("label", label);
		ventana.setLayout(orden);
		//ventana.add(label);
		ventana.setModal(false);
		ventana.setVisible(true);
		ventana.setAlwaysOnTop(true);
		
	}
	

	public static void launcher(String comando) {
		String os = new java.util.StringTokenizer(System.getProperty("os.name"))
				.nextToken();
		
		Process p = null;
		try {
			if (os.equals("Windows")) {
				p = Runtime.getRuntime().exec(comando + ".exe");
				
			} else {
				if (os.equals("Mac")) {
					p = Runtime.getRuntime().exec(
							"open /Applications/" + comando + ".app");
				} else {
					if (os.equals("Linux")) {
						p = Runtime.getRuntime().exec(comando);
						//Process q = Runtime.getRuntime().exec("wmctrl -r " + comando + " -e 1,0,0,width, height");
					} else {
						// SO desconocido
					}
				}
			}
		} catch (Exception e) {
			popup(0, "Error: La aplicacion que intenta ejecutar es desconocida");

		}
	}

	public static void launcher(String comando, String argumentos) {
		String os = new java.util.StringTokenizer(System.getProperty("os.name"))
				.nextToken();
		String[] args = new String[2];
		args[1] = argumentos;
		Process p = null;
		try {
			if (os.equals("Windows")) {
				args[0] = comando + ".exe";
				p = Runtime.getRuntime().exec(args);
			} else {
				if (os.equals("Mac")) {
					args[0] = "open /Applications/" + comando + ".app";
					p = Runtime.getRuntime().exec(args);
				} else {
					if (os.equals("Linux")) {
						args[0] = comando;
						p = Runtime.getRuntime().exec(args);
					} else {
						// SO desconocido
					}
				}
			}
		} catch (Exception e) {
			popup(0, "Error: La aplicacion que intenta ejecutar es desconocida");

		}
	}
	
	
	
	
	
	public static boolean contiene(String largo, String corto) {
		
		return largo.contains(corto.subSequence(0, corto.length()));
	}

	public static void guardarXML(Document documento, String ruta) {

		try {
			TransformerFactory transFactory = TransformerFactory.newInstance();
			Transformer transformer = transFactory.newTransformer();

			DOMSource source = new DOMSource(documento);

			File newXML = new File(ruta);
			FileOutputStream os = new FileOutputStream(newXML);
			StreamResult result = new StreamResult(os);
			transformer.transform(source, result);
		} catch (Exception e) {
			Util.popup(0, "Error: no se ha podido modificar el fichero xml");
		}
	}

	public static void teclearString(String s) {
		try {
			Robot robot = new Robot();
			char[] cadena = s.toCharArray();

			for (int i = 0; i < cadena.length; i++) {
				switch ((int) cadena[i]) {
				case 'a':
					robot.keyPress(KeyEvent.VK_A);
					robot.keyRelease(KeyEvent.VK_A);
					break;
				case 'b':
					robot.keyPress(KeyEvent.VK_B);
					robot.keyRelease(KeyEvent.VK_B);
					break;

				case 'c':
					robot.keyPress(KeyEvent.VK_C);
					robot.keyRelease(KeyEvent.VK_C);
					break;

				case 'd':
					robot.keyPress(KeyEvent.VK_D);
					robot.keyRelease(KeyEvent.VK_D);
					break;

				case 'e':
					robot.keyPress(KeyEvent.VK_E);
					robot.keyRelease(KeyEvent.VK_E);
					break;

				case 'f':
					robot.keyPress(KeyEvent.VK_F);
					robot.keyRelease(KeyEvent.VK_F);
					break;

				case 'g':
					robot.keyPress(KeyEvent.VK_G);
					robot.keyRelease(KeyEvent.VK_G);
					break;

				case 'h':
					robot.keyPress(KeyEvent.VK_H);
					robot.keyRelease(KeyEvent.VK_H);
					break;

				case 'i':
					robot.keyPress(KeyEvent.VK_I);
					robot.keyRelease(KeyEvent.VK_I);
					break;

				case 'j':
					robot.keyPress(KeyEvent.VK_J);
					robot.keyRelease(KeyEvent.VK_J);
					break;

				case 'k':
					robot.keyPress(KeyEvent.VK_K);
					robot.keyRelease(KeyEvent.VK_K);
					break;

				case 'l':
					robot.keyPress(KeyEvent.VK_L);
					robot.keyRelease(KeyEvent.VK_L);
					break;

				case 'm':
					robot.keyPress(KeyEvent.VK_M);
					robot.keyRelease(KeyEvent.VK_M);
					break;

				case 'n':
					robot.keyPress(KeyEvent.VK_N);
					robot.keyRelease(KeyEvent.VK_N);
					break;

				case 'ñ':
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);

	                robot.keyPress(KeyEvent.VK_F);
	                robot.keyRelease(KeyEvent.VK_F);
	                robot.keyPress(KeyEvent.VK_1);
	                robot.keyRelease(KeyEvent.VK_1);
	                
	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);

					break;

				case 'o':
					robot.keyPress(KeyEvent.VK_O);
					robot.keyRelease(KeyEvent.VK_O);
					break;

				case 'p':
					robot.keyPress(KeyEvent.VK_P);
					robot.keyRelease(KeyEvent.VK_P);
					break;

				case 'q':
					robot.keyPress(KeyEvent.VK_Q);
					robot.keyRelease(KeyEvent.VK_Q);
					break;

				case 'r':
					robot.keyPress(KeyEvent.VK_R);
					robot.keyRelease(KeyEvent.VK_R);
					break;

				case 's':
					robot.keyPress(KeyEvent.VK_S);
					robot.keyRelease(KeyEvent.VK_S);
					break;

				case 't':
					robot.keyPress(KeyEvent.VK_T);
					robot.keyRelease(KeyEvent.VK_T);
					break;

				case 'u':
					robot.keyPress(KeyEvent.VK_U);
					robot.keyRelease(KeyEvent.VK_U);
					break;

				case 'v':
					robot.keyPress(KeyEvent.VK_V);
					robot.keyRelease(KeyEvent.VK_V);
					break;

				case 'w':
					robot.keyPress(KeyEvent.VK_W);
					robot.keyRelease(KeyEvent.VK_W);
					break;

				case 'y':
					robot.keyPress(KeyEvent.VK_Y);
					robot.keyRelease(KeyEvent.VK_Y);
					break;

				case 'z':
					robot.keyPress(KeyEvent.VK_Z);
					robot.keyRelease(KeyEvent.VK_Z);
					break;

				case '0':
					robot.keyPress(KeyEvent.VK_0);
					robot.keyRelease(KeyEvent.VK_0);
					break;

				case '1':
					robot.keyPress(KeyEvent.VK_1);
					robot.keyRelease(KeyEvent.VK_1);
					break;

				case '2':
					robot.keyPress(KeyEvent.VK_2);
					robot.keyRelease(KeyEvent.VK_2);
					break;

				case '3':
					robot.keyPress(KeyEvent.VK_3);
					robot.keyRelease(KeyEvent.VK_3);
					break;

				case '4':
					robot.keyPress(KeyEvent.VK_4);
					robot.keyRelease(KeyEvent.VK_4);
					break;

				case '5':
					robot.keyPress(KeyEvent.VK_5);
					robot.keyRelease(KeyEvent.VK_5);
					break;

				case '6':
					robot.keyPress(KeyEvent.VK_6);
					robot.keyRelease(KeyEvent.VK_6);
					break;

				case '7':
					robot.keyPress(KeyEvent.VK_7);
					robot.keyRelease(KeyEvent.VK_7);
					break;

				case '8':
					robot.keyPress(KeyEvent.VK_8);
					robot.keyRelease(KeyEvent.VK_8);
					break;

				case '9':
					robot.keyPress(KeyEvent.VK_9);
					robot.keyRelease(KeyEvent.VK_9);
					break;
					
				case 'á':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					
					
	                robot.keyPress(KeyEvent.VK_E);
	                robot.keyRelease(KeyEvent.VK_E);
	                robot.keyPress(KeyEvent.VK_1);
	                robot.keyRelease(KeyEvent.VK_1);


	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case 'é':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					
					
	                robot.keyPress(KeyEvent.VK_E);
	                robot.keyRelease(KeyEvent.VK_E);
	                robot.keyPress(KeyEvent.VK_9);
	                robot.keyRelease(KeyEvent.VK_9);


	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;

				case 'í':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
						
	                robot.keyPress(KeyEvent.VK_E);
	                robot.keyRelease(KeyEvent.VK_E);
	                robot.keyPress(KeyEvent.VK_D);
	                robot.keyRelease(KeyEvent.VK_D);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case 'ó':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					
					
	                robot.keyPress(KeyEvent.VK_F);
	                robot.keyRelease(KeyEvent.VK_F);
	                robot.keyPress(KeyEvent.VK_3);
	                robot.keyRelease(KeyEvent.VK_3);


	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case 'ú':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					
					
	                robot.keyPress(KeyEvent.VK_F);
	                robot.keyRelease(KeyEvent.VK_F);
	                robot.keyPress(KeyEvent.VK_A);
	                robot.keyRelease(KeyEvent.VK_A);


	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case 'Á':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
										
	                robot.keyPress(KeyEvent.VK_C);
	                robot.keyRelease(KeyEvent.VK_C);
	                robot.keyPress(KeyEvent.VK_1);
	                robot.keyRelease(KeyEvent.VK_1);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case 'É':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					
					
	                robot.keyPress(KeyEvent.VK_C);
	                robot.keyRelease(KeyEvent.VK_C);
	                robot.keyPress(KeyEvent.VK_9);
	                robot.keyRelease(KeyEvent.VK_9);


	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;

				case 'Í':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					
					
	                robot.keyPress(KeyEvent.VK_C);
	                robot.keyRelease(KeyEvent.VK_C);
	                robot.keyPress(KeyEvent.VK_D);
	                robot.keyRelease(KeyEvent.VK_D);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case 'Ó':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
										
	                robot.keyPress(KeyEvent.VK_D);
	                robot.keyRelease(KeyEvent.VK_D);
	                robot.keyPress(KeyEvent.VK_3);
	                robot.keyRelease(KeyEvent.VK_3);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case 'Ú':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
										
	                robot.keyPress(KeyEvent.VK_D);
	                robot.keyRelease(KeyEvent.VK_D);
	                robot.keyPress(KeyEvent.VK_A);
	                robot.keyRelease(KeyEvent.VK_A);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
					
				case '¿':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
										
	                robot.keyPress(KeyEvent.VK_B);
	                robot.keyRelease(KeyEvent.VK_B);
	                robot.keyPress(KeyEvent.VK_F);
	                robot.keyRelease(KeyEvent.VK_F);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case '?':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
										
	                robot.keyPress(KeyEvent.VK_3);
	                robot.keyRelease(KeyEvent.VK_3);
	                robot.keyPress(KeyEvent.VK_F);
	                robot.keyRelease(KeyEvent.VK_F);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case '~':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
									
	                robot.keyPress(KeyEvent.VK_7);
	                robot.keyRelease(KeyEvent.VK_7);
	                robot.keyPress(KeyEvent.VK_E);
	                robot.keyRelease(KeyEvent.VK_E);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case '{':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					/*
	                robot.keyPress(KeyEvent.VK_ALT);
	                robot.keyPress(KeyEvent.VK_NUMPAD1);
	                robot.keyRelease(KeyEvent.VK_NUMPAD1);
	                robot.keyPress(KeyEvent.VK_NUMPAD2);
	                robot.keyRelease(KeyEvent.VK_NUMPAD2);
	                robot.keyPress(KeyEvent.VK_NUMPAD3);
	                robot.keyRelease(KeyEvent.VK_NUMPAD3);
	                robot.keyRelease(KeyEvent.VK_ALT);*/
	                
	                robot.keyPress(KeyEvent.VK_7);
	                robot.keyRelease(KeyEvent.VK_7);
	                robot.keyPress(KeyEvent.VK_B);
	                robot.keyRelease(KeyEvent.VK_B);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case '}':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					
	                /*robot.keyPress(KeyEvent.VK_ALT);
	                robot.keyPress(KeyEvent.VK_NUMPAD1);
	                robot.keyRelease(KeyEvent.VK_NUMPAD1);
	                robot.keyPress(KeyEvent.VK_NUMPAD2);
	                robot.keyRelease(KeyEvent.VK_NUMPAD2);
	                robot.keyPress(KeyEvent.VK_NUMPAD5);
	                robot.keyRelease(KeyEvent.VK_NUMPAD5);
	                robot.keyRelease(KeyEvent.VK_ALT);*/
	                
	                robot.keyPress(KeyEvent.VK_7);
	                robot.keyRelease(KeyEvent.VK_7);
	                robot.keyPress(KeyEvent.VK_D);
	                robot.keyRelease(KeyEvent.VK_D);
	                

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
				case '|':
					
	                robot.keyPress(KeyEvent.VK_CONTROL);
	                robot.keyPress(KeyEvent.VK_SHIFT);
	                robot.keyPress(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_U);
	                robot.keyRelease(KeyEvent.VK_SHIFT);
	                robot.keyRelease(KeyEvent.VK_CONTROL);
					/*
	                robot.keyPress(KeyEvent.VK_ALT);
	                robot.keyPress(KeyEvent.VK_NUMPAD1);
	                robot.keyRelease(KeyEvent.VK_NUMPAD1);
	                robot.keyPress(KeyEvent.VK_NUMPAD2);
	                robot.keyRelease(KeyEvent.VK_NUMPAD2);
	                robot.keyPress(KeyEvent.VK_NUMPAD4);
	                robot.keyRelease(KeyEvent.VK_NUMPAD4);
	                robot.keyRelease(KeyEvent.VK_ALT);*/
	                
	                robot.keyPress(KeyEvent.VK_7);
	                robot.keyRelease(KeyEvent.VK_7);
	                robot.keyPress(KeyEvent.VK_C);
	                robot.keyRelease(KeyEvent.VK_C);

	                robot.keyPress(KeyEvent.VK_SPACE);
	                robot.keyRelease(KeyEvent.VK_SPACE);
	                
					break;
					
					
				case '/':robot.keyPress(KeyEvent.VK_SLASH);
                		robot.keyRelease(KeyEvent.VK_SLASH);
					
					
					doType(KeyEvent.VK_SLASH); break;
										
					
				case 'A': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_A); break;
		        case 'B': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_B); break;
		        case 'C': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_C); break;
		        case 'D': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_D); break;
		        case 'E': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_E); break;
		        case 'F': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_F); break;
		        case 'G': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_G); break;
		        case 'H': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_H); break;
		        case 'I': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_I); break;
		        case 'J': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_J); break;
		        case 'K': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_K); break;
		        case 'L': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_L); break;
		        case 'M': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_M); break;
		        case 'N': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_N); break;
		        case 'O': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_O); break;
		        case 'P': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_P); break;
		        case 'Q': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_Q); break;
		        case 'R': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_R); break;
		        case 'S': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_S); break;
		        case 'T': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_T); break;
		        case 'U': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_U); break;
		        case 'V': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_V); break;
		        case 'W': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_W); break;
		        case 'X': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_X); break;
		        case 'Y': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_Y); break;
		        case 'Z': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_Z); break;
		        case '`': doType(KeyEvent.VK_BACK_QUOTE); break;
		        case '-': doType(KeyEvent.VK_MINUS); break;
		        case '=': doType(KeyEvent.VK_EQUALS); break;

		        case '!': doType(KeyEvent.VK_EXCLAMATION_MARK); break;
		        case '@': doType(KeyEvent.VK_AT); break;
		        case '#': doType(KeyEvent.VK_NUMBER_SIGN); break;
		        case '$': doType(KeyEvent.VK_DOLLAR); break;
		        case '%': doType(KeyEvent.VK_SHIFT, KeyEvent.VK_5); break;
		        case '^': doType(KeyEvent.VK_CIRCUMFLEX); break;
		        case '&': doType(KeyEvent.VK_AMPERSAND); break;
		        case '*': doType(KeyEvent.VK_ASTERISK); break;
		        case '(': doType(KeyEvent.VK_LEFT_PARENTHESIS); break;
		        case ')': doType(KeyEvent.VK_RIGHT_PARENTHESIS); break;
		        case '_': doType(KeyEvent.VK_UNDERSCORE); break;
		        case '+': doType(KeyEvent.VK_PLUS); break;
		        case '\t': doType(KeyEvent.VK_TAB); break;
		        case '\n': doType(KeyEvent.VK_ENTER); break;
		        case '[': doType(KeyEvent.VK_OPEN_BRACKET); break;
		        case ']': doType(KeyEvent.VK_CLOSE_BRACKET); break;
		        case '\\': doType(KeyEvent.VK_BACK_SLASH); break;
		        case ';': doType(KeyEvent.VK_SEMICOLON); break;
		        case ':': doType(KeyEvent.VK_COLON); break;
		        case '\'': doType(KeyEvent.VK_QUOTE); break;
		        case '"': doType(KeyEvent.VK_QUOTEDBL); break;
		        case ',': doType(KeyEvent.VK_COMMA); break;
		        case '<': doType(KeyEvent.VK_LESS); break;
		        case '.': doType(KeyEvent.VK_PERIOD); break;
		        case '>': doType(KeyEvent.VK_GREATER); break;
		        case ' ': doType(KeyEvent.VK_SPACE); break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
    private static void doType(int... keyCodes) {
       doType(keyCodes, 0, keyCodes.length);
    }

    private static void doType(int[] keyCodes, int offset, int length) {
        if (length == 0) {
                return;
        }
        try{
        Robot robot = new Robot();
        robot.keyPress(keyCodes[offset]);
        doType(keyCodes, offset + 1, length - 1);
        robot.keyRelease(keyCodes[offset]);
        }catch(Exception e){
        	
        	
        	
        }
    }
	
    public static Vector<Integer> ReconocerCodigo(String teclasEspeciales, Vector<Integer> teclas){
    	
		char[] cadena = teclasEspeciales.toCharArray();
		Vector<Integer> _teclas = teclas;

		for (int i = 0; i < cadena.length; i++) {

			switch ((int) cadena[i]) {
			case 'a':
				teclas.add(KeyEvent.VK_A);
				break;
			case 'b':
				teclas.add(KeyEvent.VK_B);
				break;

			case 'c':
				teclas.add(KeyEvent.VK_C);
				break;

			case 'd':
				teclas.add(KeyEvent.VK_D);
				break;

			case 'e':
				teclas.add(KeyEvent.VK_E);
				break;

			case 'f':
				teclas.add(KeyEvent.VK_F);
				break;

			case 'g':
				teclas.add(KeyEvent.VK_G);
				break;

			case 'h':
				teclas.add(KeyEvent.VK_H);
				break;

			case 'i':
				teclas.add(KeyEvent.VK_I);
				break;

			case 'j':
				teclas.add(KeyEvent.VK_J);
				break;

			case 'k':
				teclas.add(KeyEvent.VK_K);
				break;

			case 'l':
				teclas.add(KeyEvent.VK_L);
				break;

			case 'm':
				teclas.add(KeyEvent.VK_M);
				break;

			case 'n':
				teclas.add(KeyEvent.VK_N);
				break;

			case 'o':
				teclas.add(KeyEvent.VK_O);
				break;

			case 'p':
				teclas.add(KeyEvent.VK_P);
				break;

			case 'q':
				teclas.add(KeyEvent.VK_Q);
				break;

			case 'r':
				teclas.add(KeyEvent.VK_R);
				break;

			case 's':
				teclas.add(KeyEvent.VK_S);
				break;

			case 't':
				teclas.add(KeyEvent.VK_T);
				break;

			case 'u':
				teclas.add(KeyEvent.VK_U);
				break;

			case 'v':
				teclas.add(KeyEvent.VK_V);
				break;

			case 'w':
				teclas.add(KeyEvent.VK_W);
				break;

			case 'y':
				teclas.add(KeyEvent.VK_Y);
				break;

			case 'z':
				teclas.add(KeyEvent.VK_Z);
				break;

			case '0':
				teclas.add(KeyEvent.VK_0);
				break;

			case '1':
				teclas.add(KeyEvent.VK_1);
				break;

			case '2':
				teclas.add(KeyEvent.VK_2);
				break;

			case '3':
				teclas.add(KeyEvent.VK_3);
				break;

			case '4':
				teclas.add(KeyEvent.VK_4);
				break;

			case '5':
				teclas.add(KeyEvent.VK_5);
				break;

			case '6':
				teclas.add(KeyEvent.VK_6);
				break;

			case '7':
				teclas.add(KeyEvent.VK_7);
				break;

			case '8':
				teclas.add(KeyEvent.VK_8);
				break;

			case '9':
				teclas.add(KeyEvent.VK_9);
				break;
				
			}
		}
	
    	return _teclas;
    	
    }
    
    public static void teclearVector(Vector<Integer>teclas){
    	
    	try {
			Robot robot = new Robot();
			for (int i = 0; i < teclas.size(); i++)
				robot.keyPress(teclas.get(i).intValue());

			for (int j = 0; j < teclas.size(); j++)
				robot.keyRelease(teclas.get(teclas.size() - j - 1).intValue());
		} catch (Exception e) {
			e.printStackTrace();
		}
    	
    }

	public static void teclearEspecial(Vector<Integer> teclasEspeciales,
			String cadena) {
		try {
			Robot robot = new Robot();
			for (int i = 0; i < teclasEspeciales.size(); i++)
				robot.keyPress(teclasEspeciales.get(i).intValue());
			if (cadena != null)
				teclearString(cadena);
			for (int j = 0; j < teclasEspeciales.size(); j++)
				robot.keyRelease(teclasEspeciales.get(
						teclasEspeciales.size() - j - 1).intValue());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void pulsar(Integer tecla){
		
		try{
			Robot robot = new Robot();
			robot.keyPress(tecla);
			
		}catch(Exception e){
			
			e.printStackTrace();
		}
		
	}
	
	public static void soltar(Integer tecla){
		
		try{
			Robot robot = new Robot();
			robot.keyRelease(tecla);
			
		}catch(Exception e){
			
			e.printStackTrace();
		}
		
		
	}
	
	public static void cerrarVentana(){
		
		try{
			Robot robot = new Robot();
			robot.keyPress(KeyEvent.VK_ALT);
			robot.keyPress(KeyEvent.VK_F4);
			robot.keyRelease(KeyEvent.VK_F4);
			robot.keyRelease(KeyEvent.VK_ALT);


			
		}catch(Exception e){
			
			e.printStackTrace();
		}
		
		
	}
	

	
	
	public static JLabel BotonInvisible(String imagen, BotonPersonalizado b){
		JLabel boton = new JLabel();
		boton.setIcon(new ImageIcon(imagen));
		boton.setOpaque(false);
		return boton;
	}
	
	
	
	public static BotonPersonalizado BotonImagen(BotonTO _boton, TecladoReal teclado) {

		BotonPersonalizado boton = new BotonPersonalizado(Color.white, new Color(205,150,0),_boton,teclado);

		return boton;
	}
	
	public static BotonPersonalizado BotonImagen(BotonTO _boton) {

		BotonPersonalizado boton = new BotonPersonalizado(Color.white, new Color(205,150,0),_boton);

		return boton;
	}
	
    public static void redimensionar(BotonPersonalizado boton){
    	
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
    	JLabel etiqueta = (JLabel)boton.getLabelImagen();
    	ImageIcon imagenActual = (ImageIcon)etiqueta.getIcon();
    	int alto = imagenActual.getIconHeight();
    	int ancho = imagenActual.getIconWidth();
    	double factorEscala = (double)alto /  ((screenSize.getHeight() / 3)-80);


		ancho = ((int) (ancho / factorEscala));
		alto = ((int) (((screenSize.getHeight() / 3)-80)));

		Image redimensionada = imagenActual.getImage().getScaledInstance(ancho,
				alto, Image.SCALE_DEFAULT);
		etiqueta.setIcon(new ImageIcon(redimensionada));
    	
    }
	
    public static List<String> ListarTecladosUsuario(String usuario){
    	
    	PlantillaFacade fachada = new PlantillaFacade();
    	List <String> teclados = new ArrayList<String>();
    	Configuracion.instancia().setDirUsuarioActual(Configuracion.instancia().getDirUsuarios() + usuario);
    	
    	File dir = new File(Configuracion.instancia().getDirUsuarioActual());
    	File[] subdir = dir.listFiles();
    	
    	
    	for(int i=0;i<subdir.length;i++){
    		
    		if(subdir[i].isDirectory()){
    			String nombre = fachada.GetName(subdir[i].getAbsolutePath());
    			teclados.add(nombre);
    		}
    		
    	}
    	
    	return teclados;
    }
    
    public static PlantillaTO crearTeclado(int cols, int filas, String nombreTeclado){
    	
    	PlantillaTO teclado = new PlantillaTO();
    	List<BotonTO> botones = new ArrayList<BotonTO>();
    	int k = 1;
    	for(int i = 0; i < filas; i++){
    		
    		for(int j=0; j< cols; j++){
    			if(k!=cols*filas){
    			BotonTO b1 = new BotonTO();
    			b1.setNombreBoton("boton"+k);
    			b1.setTextoBoton("boton"+k);
    			b1.setColumnasOcupa("1");
    			b1.setFilasOcupa("1");
    			b1.setPosicionFila(new Integer(i).toString());
    			b1.setPosicionColumna(new Integer(j).toString());
    			b1.setNombreColorBorde(new Integer((Color.black.getRGB())).toString());
    			b1.setNombreColorFondo(new Integer((Color.gray.getRGB())).toString());
    			b1.setNombreColorMouseDown(new Integer((Color.DARK_GRAY.getRGB())).toString());
    			b1.setNombreColorMouseOver(new Integer((Color.orange.getRGB())).toString());
    			b1.setNombreColorFuente(new Integer((Color.black.getRGB())).toString());
    			b1.setNombreFuente("Verdana");
    			b1.setTamanoFuente("12");
    			b1.setBorderSize("1");
    			k++;
    			botones.add(b1);}
    			
    		}
    		
    	}
    	
    	BotonTO b4 = botonSalir(filas-1, cols-1);
    	/*b4.setNombreBoton("salir");
    	b4.setTextoBoton("salir");
    	b4.setColumnasOcupa("1");
    	b4.setFilasOcupa("1");
    	b4.setPosicionFila(new Integer(filas-1).toString());
    	b4.setPosicionColumna(new Integer(cols-1).toString());
    	b4.setNombreColorBorde(new Integer((Color.gray.getRGB())).toString());
    	b4.setNombreColorFondo(new Integer((Color.red.getRGB())).toString());
    	b4.setNombreColorMouseDown(new Integer((Color.DARK_GRAY.getRGB())).toString());
    	b4.setNombreColorMouseOver(new Integer((Color.orange.getRGB())).toString());
    	b4.setNombreColorFuente(new Integer((Color.black.getRGB())).toString());
    	b4.setNombreFuente("Verdana");
    	b4.setTamanoFuente("12");
    	b4.setBorderSize("2");*/
    	botones.add(b4);
    	
    	
    	teclado.setNumeroColumnas(new Integer(cols).toString());
    	teclado.setNumeroFilas(new Integer(filas).toString());
    	teclado.setPosicionInicial("LIBRE");
    	teclado.setAltoTeclado("300");
    	teclado.setAnchoTeclado("600");
    	
    	teclado.setNombrePlantilla(nombreTeclado);
      	teclado.setListaBotones(botones);
    	
    	return teclado;
    	
    }
    
    public static BotonTO botonSalir(int posFila, int posCol){
    	

		
    	BotonTO b2 = new BotonTO();
		b2.setNombreBoton("salir");
		b2.setTextoBoton("salir");
		b2.setColumnasOcupa("1");
		b2.setFilasOcupa("1");
		b2.setPosicionFila(new Integer(posFila).toString());
		b2.setPosicionColumna(new Integer(posCol).toString());
    	b2.setNombreColorBorde(new Integer((Color.black.getRGB())).toString());
    	b2.setNombreColorFondo(new Integer((Color.red.getRGB())).toString());
    	b2.setNombreColorMouseDown(new Integer((Color.DARK_GRAY.getRGB())).toString());
    	b2.setNombreColorMouseOver(new Integer((Color.orange.getRGB())).toString());
    	b2.setNombreColorFuente(new Integer((Color.black.getRGB())).toString());
    	AccionBotonTO accion = new AccionBotonTO();
    	accion.setGrupoAccion(AccionesEjecutar.GA_TCL_ESP_TD);
    	accion.setAccionConcreta(AccionesEjecutar.AC_TLC_ESP_CERRAR_TECLADO);
    	List<AccionBotonTO> acciones = new ArrayList<AccionBotonTO>();
    	acciones.add(accion);
    		b2.setAccionEjecutar(acciones);
		b2.setNombreFuente("Verdana");
		b2.setTamanoFuente("12");
		b2.setBorderSize("1");
		
		return b2;
    	
    }
    
    public static BotonTO botonTeclado(int posFila, int posCol){
    	
    	BotonTO b2 = new BotonTO();
		b2.setNombreBoton("boton");
		b2.setTextoBoton("boton");
		b2.setColumnasOcupa("1");
		b2.setFilasOcupa("1");
		b2.setPosicionFila(new Integer(posFila).toString());
		b2.setPosicionColumna(new Integer(posCol).toString());
    	b2.setNombreColorBorde(new Integer((Color.black.getRGB())).toString());
    	b2.setNombreColorFondo(new Integer((Color.gray.getRGB())).toString());
    	b2.setNombreColorMouseDown(new Integer((Color.DARK_GRAY.getRGB())).toString());
    	b2.setNombreColorMouseOver(new Integer((Color.orange.getRGB())).toString());
    	b2.setNombreColorFuente(new Integer((Color.black.getRGB())).toString());
		b2.setNombreFuente("Verdana");
		b2.setTamanoFuente("12");
		b2.setBorderSize("1");
		return b2;
    	
    }

    public static BotonPersonalizado BotonPreview(BotonTO _boton, PaginaEntornoCreacionTeclados frame, JFrame ventana) {

		BotonPersonalizado boton = new BotonPersonalizado(Color.white, new Color(205,150,0),_boton,"preview");
		
		boton.addMouseListener(new accionRaton(boton, new Color(new Integer(_boton.getNombreColorMouseOver()))));
		boton.addMouseListener(new AccionSeleccionBoton(boton, frame, ventana));
		//boton.addActionListener(new AsignarAccion(boton, _boton.getAccionEjecutar()));
		return boton;
	}
    
	public static String BuscarClave(String key,Enumeration<String> claves){
		
		String origen="";
		
		while(claves.hasMoreElements()){
			String clave = claves.nextElement();
			if(key.equals(ResourceBundle.getBundle("internacionalizacion/Acciones").getString(clave))){

				origen = clave;
			}
					
		}
		
		
		return origen;
	}
	
	public static String RecuperarExtension(String ruta){
		
	      String extension="";
	      int dotPos = ruta.lastIndexOf(".");
	      if(dotPos!=-1){
	      extension = ruta.substring(dotPos);}
	      return extension;
	}
	
	public static void cerrarTeclado(TecladoReal teclado){
		
		
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension sc = tk.getScreenSize();
		//teclado.get_contenedor().setPreferredSize(new Dimension(10,37));
		if(Configuracion.instancia().getTest().equals("Si")){
			teclado.get_contenedor().setContentPane(new PaginaUsuarios(teclado.get_contenedor(), 0, 13,true,Configuracion.instancia().getUser()));

			
		}else{
		teclado.get_contenedor().setContentPane(new PaginaUsuarios(teclado.get_contenedor(), 0, 13));}
		if(teclado.is_barrido()) teclado.matarBarrido();
		teclado.get_contenedor().pack();
		teclado.get_contenedor().repaint();
		
	}
	
	public static void desactivarUsuario(BotonPersonalizado boton){
		
		
		ActionListener[] lista = boton.getActionListeners();
		
		for(int i = 0; i< lista.length; i++){
			
			boton.removeActionListener(lista[i]);
		}
		MouseListener[] mouse = boton.getMouseListeners();
		for(int i = 0; i< lista.length; i++){
			
			boton.removeMouseListener(mouse[i]);
		}
	}
	
	public static void activarUsuario(ActionListener[] actions, MouseListener[] mouseActions, BotonPersonalizado boton){
	
		for(int i = 0; i< actions.length; i++){
			
			boton.addActionListener(actions[i]);
		}
		for(int i = 0; i< mouseActions.length; i++){
			
			boton.addMouseListener(mouseActions[i]);
		}
		

	}
	
	public static void redimensionarVentana(){
		
		String[] args = new String[2];
		args[0] = "wmctrl";
		String argumentos="wmctrl ";
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		
		
  	 	if(Configuracion.instancia().getPosicion().equals("SUPERIOR")){
	   	 	
  	 		argumentos =argumentos + "-r :ACTIVE: -e 0,0,"+Configuracion.instancia().getAltoTeclado()+","+screenSize.width+","+(screenSize.height- new Integer(Configuracion.instancia().getAltoTeclado())-40);
  			Process p;
  			try{
  			p = Runtime.getRuntime().exec("wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz");
  			}catch(Exception e){
  				
  				
  			}
	 	}else{
	 		if (Configuracion.instancia().getPosicion().equals("INFERIOR")){
	 			
	 		
	  	 		argumentos =argumentos + "-r :ACTIVE: -e 0,0,0"+","+screenSize.width+","+(screenSize.height- new Integer(Configuracion.instancia().getAltoTeclado())-40);
	  	 		Process p;
	  			try{
	  			p = Runtime.getRuntime().exec("wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz");
	  			}catch(Exception e){
	  				
	  				
	  			}
	 		

	 		}else{
	 			
	 			if(Configuracion.instancia().getPosicion().equals("PANTALLA_COMPLETA")){
	 				
	 				
	 			}else{
	 				
	 				if(Configuracion.instancia().getPosicion().equals("LIBRE")){
	 		   	 	
	 					
	 				}
		
	 			}
	 		}
	 	}
		
		args[1] = argumentos;
		Process p;
		try{
		p = Runtime.getRuntime().exec(argumentos);
		}catch(Exception e){
			
			
		}
		
		
	}
	
	public static void redimensionarVentana(String ventana){
		
		
		
	}
	
}
